package net.mikoo.seals.api.model.use;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.common.enums.CensorStatusEnum;
import net.mikoo.seals.common.model.PageModel;
import net.mikoo.seals.model.DevicesAct;

public class UseActsResponse extends BaseResponse {

	private static final long serialVersionUID = 6545671643449105489L;

	private List<ActInfo> actList;
	
	public List<ActInfo> getActList() {
		return actList;
	}

	public void setActList(List<ActInfo> actList) {
		this.actList = actList;
	}

	public static UseActsResponse valueOf(PageModel<DevicesAct> pm) {
		UseActsResponse result = new UseActsResponse();
		if(pm == null || pm.getDatas() == null) {
			return result;
		}
		
		List<ActInfo> actList = new ArrayList<ActInfo>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for(DevicesAct actInfo : pm.getDatas()) {
			if(actInfo == null) {
				continue;
			}
			ActInfo act = new ActInfo();
			act.setActId(actInfo.getDevicesActId());
			if(actInfo.getSeal() != null) {
				act.setSealName(actInfo.getSeal().getSealName());
			}
			if(actInfo.getUpdateTime() != null) {
				act.setUseTime(sdf.format(actInfo.getUpdateTime()));
			}
			
			CensorStatusEnum censorStatus = CensorStatusEnum.getByCode(actInfo.getCensorStatus());
			if(censorStatus != null) {
				act.setCensorStatus(censorStatus.getCode());
				act.setCensorStatusName(censorStatus.getMessage());
			}
			
			actList.add(act);
		}
		
		result.setActList(actList);
		return result;
	}

	private static class ActInfo{
		
		private long actId;
		
		private String sealName;
		
		private String useTime;
		
		private String censorStatus;
		
		private String censorStatusName;

		public long getActId() {
			return actId;
		}

		public void setActId(long actId) {
			this.actId = actId;
		}

		public String getSealName() {
			return sealName;
		}

		public void setSealName(String sealName) {
			this.sealName = sealName;
		}

		public String getUseTime() {
			return useTime;
		}

		public void setUseTime(String useTime) {
			this.useTime = useTime;
		}

		public String getCensorStatus() {
			return censorStatus;
		}

		public void setCensorStatus(String censorStatus) {
			this.censorStatus = censorStatus;
		}

		public String getCensorStatusName() {
			return censorStatusName;
		}

		public void setCensorStatusName(String censorStatusName) {
			this.censorStatusName = censorStatusName;
		}
	}
}
